import Vue from 'vue'
import App from './App.vue'
import router from './router'

import axios from 'axios'
Vue.prototype.$axios = axios  //引入axios挂载到vue原型

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);  //引入elementUi库

//设置默认的 api 域名基准路径
axios.defaults.baseURL = 'http://127.0.0.1:3000'
// axios.defaults.baseURL = 'http://liangwei.tech:3000'

//设置全局路由守卫
//to目标路由
//from从什么路由跳转
//next 一定要放行
import {Message} from 'element-ui'
router.beforeEach((to,from,next)=>{
  if(to.path == '/'){
    if(localStorage.getItem('token')){
      next()
    }else{
      Message({
        message: '给老子登录',
        type: 'warning'
      });
      router.push('/login')
    }
  }else{
    next()
  }
})

Vue.config.productionTip = false

new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')
